package chapters18;

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by xinxuchu on 2020/2/5.
 * Thread.sleep(6000) 线程持续时间，并不能理解为暂停时间
 * 该时间内，线程的定时任务还是会跑！！！
 */
public class BasicTimer {

    static class DelayTas extends TimerTask{

        @Override
        public void run() {
            System.out.println("delay task!");
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Timer timer = new Timer();
//        timer.schedule(new DelayTas(),3000);
        timer.schedule(new DelayTas(),new Date(),1000);
        Thread.sleep(6000);//更像是线程持续6秒，期间定时任务还是会跑！
        timer.cancel();
    }
}
